﻿
using System ;
using System.Data ;
using System.Collections.Generic ;

using MskEdit.Msk.Model ;
using MskEdit.Dxf.Model ;
using MskEdit.Sdk ;


namespace MskEdit.Model
{
    public class Project
    {
        private MskDocument     anyMskDocument_ ;
        private DxfDocument[]   anyDxfDocuments_ ;
        
        
        public Project( MskDocument mskDocument, DxfDocument[] dxfDocuments ) {
            anyMskDocument_    = mskDocument ;
            anyDxfDocuments_   = dxfDocuments ;
        }
        
        
        public MskDocument AnyMskDocument {
            get { return anyMskDocument_ ; }
        }
        
        
        public DxfDocument[] AnyDxfDocuments {
            get { return anyDxfDocuments_ ; }
        }       
        
        
        public DxfAttrDataTable tryGetDxfAttrDataTable( string attrdefTag, string attribTag, DxfAttrDataTable fallbackValue ) {
        
            if ( anyDxfDocuments_ == null )
                return fallbackValue ;
                
            if ( anyDxfDocuments_.Length == 0 )
                return fallbackValue ;
                
            var dxfAttrDataTable = new DxfAttrDataTable() ;
            
            foreach ( DxfDocument dxfDocument in anyDxfDocuments_ ) {
            
                var docName       = dxfDocument.Name ;
                var attrdefPrompt = dxfDocument.TryGetAttrdefPrompt( attrdefTag, attribTag, "<no attrdef>" ) ;
                var attribText    = dxfDocument.TryGetAttribText( attribTag, "<no attrib>" ) ;
                
                var dataRow = dxfAttrDataTable.NewRow( docName, attrdefPrompt, attribText) ;
                dxfAttrDataTable.Rows.Add( dataRow ) ;                
            }
            
            dxfAttrDataTable.AcceptChanges() ;
            
            return dxfAttrDataTable ;
        }
    }
}
